import { defHttp } from '@/utils/http/axios';
enum Api {
  createTaskListApi = '/mv/task/createTaskList',
  listPageApi = '/mv/task/listPage',
  createTaskApi = '/mc/task/createTask',
  taskPageApi = '/mc/task/taskPage',
  uploadApi = '/file/uploadImage',
  getTaskDetailApi = '/mc/task/getDetail',
  updateTaskApi = '/mc/task/updateTask',
  detailTaskPage = '/mc/task/detailTaskPage',
  deviceToOwnerAPI = '/mc/device/deviceToOwner',
  detailTaskPageDevAPI="/mc/task/deviceTaskPage"
}

//获取订单列表信息
export function createTaskListApi(params) {
  return defHttp
    .post(
      {
        url: Api.createTaskListApi,
        params,
      },
      {
        isTransformResponse: false,
      },
    )
    .then((res) => {
      return res;
    })
    .catch((err) => {
      console.log(err, '创建任务');
    });
}

//获取任务详情
export function detailTaskPage(params) {
  params['current'] = params.page;
  params['size'] = params.pageSize;
  return defHttp
    .post(
      {
        url: Api.detailTaskPage,
        params,
      },
      {
        isTransformResponse: false,
      },
    )
    .then((res) => {
      return res;
    });
}

export function listPageApi(params) {
  params['current'] = params.page;
  params['size'] = params.pageSize;
  return defHttp
    .post(
      {
        url: Api.listPageApi,
        params,
      },
      {
        isTransformResponse: false,
      },
    )
    .then((res) => {
      const { records, total } = res.data;
      return {
        items: records, // 将数据列表赋值给 items
        total, // 直接使用 total
      };
    })
    .catch((err) => {
      console.log(err, '任务列表');
    });
}
//任务列表添加任务
export function createTaskApi(params) {
  return defHttp
    .post(
      {
        url: Api.createTaskApi,
        params,
      },
      {
        isTransformResponse: false,
      },
    )
    .then((res) => {
      return res;
    })
    .catch((err) => {
      console.log(err, '添加任务');
    });
}
//任务列表
export function taskPageApi(params) {
  params['current'] = params.page;
  params['size'] = params.pageSize;
  return defHttp
    .post(
      {
        url: Api.taskPageApi,
        params,
      },
      {
        isTransformResponse: false,
      },
    )
    .then((res) => {
      const { records, total } = res.data;
      return {
        items: records, // 将数据列表赋值给 items
        total, // 直接使用 total
      };
    })
    .catch((err) => {
      console.log(err, '任务列表');
    });
}
//上传文件

export function uploadApi(file) {
  const formData = new FormData();
  formData.append('file', file); // 直接添加文件对象

  return defHttp
    .post(
      {
        url: Api.uploadApi,
        data: formData,
        headers: {
          'Content-Type': 'multipart/form-data',
        },
      },
      {
        isTransformResponse: false,
      },
    )
    .then((res) => {
      return res;
    })
    .catch((err) => {
      console.log(err, '文件上传失败');
    });
}

//获取任务详情
export function getTaskDetailApi(params) {
  return defHttp
    .get(
      {
        url: Api.getTaskDetailApi + '?taskId=' + params,
      },
      {
        isTransformResponse: false,
      },
    )
    .then((res) => {
      return res;
    })
    .catch((err) => {
      console.log(err, '添加任务');
    });
}
//编辑任务
export function updateTaskApi(params) {
  return defHttp
    .post(
      {
        url: Api.updateTaskApi,
        params,
      },
      {
        isTransformResponse: false,
      },
    )
    .then((res) => {
      return res;
    })
    .catch((err) => {
      console.log(err, '添加任务');
    });
}

//设备备注映射表
export function deviceToOwnerAPI() {
  return defHttp
    .get(
      {
        url: Api.deviceToOwnerAPI,
      },
      {
        isTransformResponse: false,
      },
    )
    .then((res) => {
      return res;
    })
    .catch((err) => {
      console.log(err, '设备备注');
    });
}


export function detailTaskPageDevAPI(params) {
 
  return defHttp
    .post(
      {
        url: Api.detailTaskPageDevAPI,
        params,
      },
      {
        isTransformResponse: false,
      },
    )
    .then((res) => {
      return res;
    });
}
